package com.shrct.businessprocess.organization.impl;

import com.shrct.businessprocess.organization.RCEmployee;
import com.shrct.businessprocess.organization.RCEmployeeDAO;
import com.shrct.businessprocess.organization.RCEmployeeUser;
import com.shrct.businessprocess.organization.events.RCEmployeeEventsManager;
import edu.fudan.langlab.domain.security.User;
import edu.fudan.mylang.pf.BaseService;
import edu.fudan.mylang.pf.IGenericQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("com.shrct.businessprocess.organization.RCEmployeeDAO")
public class RCEmployeeDAOImpl extends BaseService implements RCEmployeeDAO {
  @Autowired
  private RCEmployeeEventsManager employeeEventsManager;
  
  public RCEmployee findByEid(final String eid) {
    IGenericQuery<RCEmployee> query=getObjectFactory().createGenericQuery(RCEmployee.class,"select e from com.shrct.businessprocess.organization.impl.RCEmployeeImpl as e   where ((e.eid) = (:eid)) and  e.active = 1      ").setParameter("eid",eid);
    RCEmployee _uniqueResult = query.uniqueResult();
    return _uniqueResult;
  }
  
  public void deleteEmployee(final RCEmployee employee) {
    User _asUser = employee.asUser();
    final RCEmployeeUser eu = ((RCEmployeeUser) _asUser);
    eu.setEmployee(null);getObjectFactory().delete(employee);
    getObjectFactory().delete(eu);
    
    this.employeeEventsManager.fireDeleted(employee);
  }
}
